﻿using RabbitMQ.Client;

namespace JT808.Gateway.RabbitMQ.Configs
{
    public class JT808ConsumerConfig
    {
        public string HostName { get; set; } = "localhost";
        public string Port { get; set; } = string.Empty;
        public string ExchangeName { get; set; } = string.Empty;
        public string RoutingKey { get; set; } = string.Empty;
        public bool PersistentDelivery { get; set; } = false;
        private ConnectionFactory? factory = null;
        public ConnectionFactory ConnectionFactory
        {
            get
            {
                if (factory == null)
                {
                    factory = new ConnectionFactory
                    {
                        HostName = HostName,
                        Port = Port.Length == 0 ? AmqpTcpEndpoint.UseDefaultPort : Convert.ToInt32(Port)
                    };
                }
                return factory;
            }
        }
    }
}
